
var __yamb_stack = [];
var base = "/js/yamb/";

function Yamb(options) {
	options = $.extend({}, options);
	
	options.lang = options.language ? options.language.toLowerCase() : "en";
	
	// get game list
	if(typeof(options.games)=="undefined") {
		alert("Nothing to play.");
		return;
	}
	
	if(typeof(options.element)=="undefined") {
		alert("Please provide a valid destination HTML element");
	}
	
	// init Yamb Object
	this.object = $.extend(true, {}, YambObject);
	
	// load JS/CSS
	var libraries2load = [
	    'js:' + root + base + 'array.lib.js',
	    'js:' + root + base + 'string.lib.js',
	    'js:' + root + base + 'lang/' + options.lang + '.js'
	];
	if($.browser.mozilla) {
		libraries2load.push('css:' + root + '/css/browser/mozilla.css');
	}else if($.browser.webkit) {
		libraries2load.push('css:' + root + '/css/browser/chrome.css');
	}else if($.browser.opera) {
		libraries2load.push('css:' + root + '/css/browser/opera.css');
	}else if($.browser.safari) {
		libraries2load.push('css:' + root + '/css/browser/safari.css');
	}else if($.browser.msie) {
		libraries2load.push('css:' + root + '/css/browser/msie.css');
	}
	for(var i=0; i<options.games.length; i++) {
		libraries2load.push('js:' + root + base + 'games/yamb.'+options.games[i]+'.js');	
	}
	options.element.addClass("loading").html("loading yamb...");
	for(var i=0; i<libraries2load.length; i++) {
		this.object.loadScript(libraries2load[i]);
	}
	YambGo(libraries2load, this, options);
}

function YambGo(libraries2load, _this, options) {
	var loaded = true;
	for(var i=0; i<libraries2load.length; i++){
		if(typeof(_this.object.loadedScripts[libraries2load[i]])=="undefined") {
			loaded = false;
			unloaded = libraries2load[i];
			break;
		}
	}
	if(!loaded) {
		var to = setTimeout(function(){
			YambGo(libraries2load, _this, options);
		}, 1000);
	}else{
		_this.object.generateUUID();
		_this.object.loadGames(options.games);
		
		$.ajax({
			url: "/yamb/layout",
			type: "post",
			data: {
				uuid: _this.object.uuid, 
				options: {
					games: options.games
				}
			},
			beforeSend: function(){
			},
			complete: function(req){
				if(req.status==200) {
					options.element.removeClass("loading").html(req.responseText);
					_this.object.interfaceInit(options.element);
					__yamb_stack[_this.object.uuid] = _this;
				}
			}
		});
	}
}

function YambBrowsePlayers(uuid) {
	var Y = __yamb_stack[uuid];
	var list = $("#player-list")
	
	list.show();
	$.ajax({
		url: "/players/browse/available",
		type: "post",
		data: {uuid: uuid},
		beforeSend: function(){
			$("#player-list .content").addClass("loading");
		},
		complete: function(req){
			if(req.status==200){
				$("#player-list .content").removeClass("loading").html(req.responseText);
			}else{
				alert(req.status + ". " + req.statusText);
			}
		}
	});	
	
	var call_index = Y.object.games.indexOf("call");
	var new_games = [];
	for(i=0; i<=call_index; i++) {
		new_games.push(Y.object.games[i]);
	}
	new_games.push("recall");
	for(i=call_index+1; i<Y.object.games.length; i++) {
		new_games.push(Y.object.games[i]);
	}
	Y.object.games = new_games;
}

function YambRestart(uuid, multiplayer, oponent_id, oponent_username) {
	var Y = __yamb_stack[uuid];
	multiplayer = multiplayer ? true : false;
	if(typeof(Y)=="undefined") {
		return;
	}
	Y.object.multiplayer = multiplayer;
	
	if(Y.object.games.indexOf("recall") > -1) {
		Y.object.games.splice(Y.object.games.indexOf("recall"), 1);
	}
	
	Y.object.holder.fadeOut({
		duration: 300,
		complete: function() {
			Y.object.holder.find(".oponent-container").remove();
			Y.object.holder.find("#yamb-end-container").hide();
			Y.object.holder.find("#yamb-end-mask").hide();
			Y.object.holder.fadeIn({
				duration: 100,
				complete: function(){
					Y.object.interfaceReset(Y.object.holder);
					Y.object.initGames();
					
					Y.object.holder.find(".controls").show();
					Y.object.holder.find(".controls .undo").hide();
					var dices = Y.object.holder.find("ul.dices li");
					dices.attr("locked", 0).attr("value", "");
					dices.each(function(){
						var classes = $(this).attr("class").split(" ");
						for(var i=0; i<classes.length; i++) {
							if(classes[i].match(/^value\d+$/)) {
								$(this).removeClass(classes[i]);
							}
						}
					});
					
					if(multiplayer) {
						$("#player-list").hide();
						var container = Y.object.holder.find(".yamb-container");
						var otherContainer = container.clone(true).addClass("oponent-container");
						otherContainer.css("width", "auto");
						otherContainer.find(".controls").remove();
						otherContainer.find(".top-items").remove();
						otherContainer.find("h1.game-title").html(oponent_username);
						otherContainer.find("td.field.toplay").removeClass("toplay");
						container.after(otherContainer);
					}
				}
			});
		}
	});
}
function YambHelp() {
	var h = $(".yamb-help .content");	
	if(!h.html().length) {
		h.html("loading...");
		$.ajax({
			url: root + base + "help.html",
			complete: function(req) {
				if(req.status == 200) {
					h.html(req.responseText);
				}else{
					h.html(req.status + ". " + req.statusText);
				}
			}
		});
	}
}
function YambCookieGet(name) {
	var nameEQ = "yamb_" + name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function YambCookieSet(name, value) {
	document.cookie = "yamb_"+name+"="+escape(value)+"; path=/";
}
function YambLogin(form){
	var msg = $(form).find(".message");
	var sbmt = $(form).find("input[type=submit]");
	$.ajax({
		url: "/yamb/login",
		type: "post",
		data: {username: $('#username').val(), password: $("#password").val()},
		beforeSend: function(){
			sbmt.attr("disabled", true);
		},
		complete: function(req) {
			sbmt.attr("disabled", false);
			if(req.status==200) {
				var user = eval("("+req.responseText+")");
				if(user.id) {
					msg.removeClass("error").addClass("ok").html("Prijava uspela.");
					location.reload();
				}else{
					msg.removeClass("ok").addClass("error").html("Prijava neuspela");
				}
				msg.slideDown();
			}else{
				alert(req.statusText);
			}
		}
	});
}
function YambLogout() {
	$.ajax({
		url: "/yamb/logout",
		beforeSend: function(){
		},
		complete: function(req){
			if(req.status==200) {
				location.reload();
			}else{
				alert(req.statusText);
			}
		}
	});
}
function YambRegister(form) {
	var firstname = $("#firstname").val();
	var lastname = $("#lastname").val();
	var email = $("#email").val();
	var username = $("#username2").val();
	var pass = $("#password2").val();
	var pass2 = $("#password22").val();
	var msg = $(form).find(".message");
	var sbmt = $(form).find("input[type=submit]");
	
	sbmt.attr("disabled", true);
	if(pass!=pass2) {
		msg.removeClass("ok").addClass("error").html("Lozinke se ne podudaraju").slideDown();
		sbmt.attr("disabled", false);
	}else if(!firstname || !lastname || !email || !username || !pass || !pass2) {
		msg.removeClass("ok").addClass("error").html("Sva polja su obavezna").slideDown();
		sbmt.attr("disabled", false);
	}else{
		$.ajax({
			url: "/yamb/register",
			type: "post",
			data: {
				firstname: firstname,
				lastname: lastname,
				email: email,
				username: username,
				password: pass
			},
			beforeSend: function() {
			},
			complete: function(req) {
				sbmt.attr("disabled", false);
				if(req.status==200) {
					var status = eval("("+req.responseText+")");
					if(!parseInt(status.code)) {
						msg.removeClass("error").addClass("ok").html(status.message).slideDown();
					}else{
						msg.removeClass("ok").addClass("error").html(status.message).slideDown();
					}
				}
			}
		});
	}
}
var YambObject = {
	uuid: "",
	holder: null,
	games: [],
	multiplayer: false,
	loadedScripts: {},
	inited: false,
	
	table: null,
	dices: [],
	btn_throw: null,
	display: null,
	disp_countdown: null,
	btn_undo: null,
	btn_undo_html: '<a href="javascript:void(0)" class="undo">undo</a>',
	
	throwCount: 0,
	rolling: [0,0,0,0,0,0],
	countdown: 0,
	locked: true,
	interval: null,
	undoed: false,
	
	loadScript: function (url) {
		var _this = this;
		var type = url.match(/^(.*?):/);
		type = ("" + type[1]).toLowerCase();
		url = url.replace(/^(.*?:)/, "");
		switch(type) {
			case "js":
				getJavaScript(url, function(data, status){_this.loadedScripts[type + ":" + url] = true;});
				break;
			case "css":
				$('<link rel="stylesheet" type="text/css" href="'+url+'" />').appendTo("head");
				_this.loadedScripts[type + ":" + url] = true;
				break;
		}
	},
	
	generateUUID: function() {
		var buffer = "qwertyuiopasdfghjklzxcvbnm1234567890";
		this.uuid = "";
		for(var i=0; i<10; i++) {
			this.uuid += buffer.substr(Math.random()*buffer.length, 1);
		}
	},
	loadGames: function(gameList) {
		for(var i=0; i<gameList.length; i++) {
			if(gameList[i]=="recall"){
				if(this.multiplayer) {
					this.games.push(gameList[i]);
				}
			}else{
				this.games.push(gameList[i]);
			}
			var game_object_name = "Yamb" + gameList[i].toTitleCase();
			eval("this." + game_object_name + " = $.extend(true,{},"+game_object_name+");");
			eval("this." + game_object_name + ".yamb = this;");
		}
	},
	initGames: function() {
		for(var i=0; i<this.games.length; i++) {
			var game_object_name = "Yamb" + this.games[i].toTitleCase();
			eval("this." + game_object_name + ".init();");
		}
	},
	interfaceInit: function(destination){
		if(this.inited) {
			return;
		}
		this.inited = true;
		var _Y = this;
		
		_Y.holder = destination;
		_Y.holder.mousedown(function(e){
			if(e.target.nodeName.toLowerCase()!="input") {
				return false;
			}
		})
		
		// submenues
		$(".submenu").click(function(){$(this).slideUp()})
		
		// table
			_Y.table = destination.find('table.yamb').eq(0);
			_Y.table.find("td.field").each(function(){
				td = $(this);
				td.click(function(){
					_Y.fieldClick($(this))
					if(!$(this).hasClass("toplay")) {
						$(this).removeClass("over-value");
					}
				});
				td.mouseover(function(){
					if(!_Y.locked && ($(this).hasClass("toplay") || $(this).hasClass("called"))) {
						$(this).addClass("over-value");
						var val = _Y.getGameValue($(this).attr("game_row"));
						$(this).html(val)
					}
				});
				td.mouseout(function(){
					if(!$(this).hasClass("played")) {
						$(this).removeClass("over-value");
						$(this).html("");
					}
				});
			});
		
		// dices
			_Y.dices = destination.find("ul.dices li");
			_Y.dices.each(function(index){
				$(this).click(function(){
					if(_Y.throwCount<3 && !_Y.isRolling()) {
						var numLocked = $(this).parent().find("li[locked=1]").length;
						if($(this).attr("value")) {
							locked = parseInt($(this).attr("locked")); locked = locked>0 ? 1 : 0;
							locked = numLocked<5 ? locked : 1;
							$(this).attr("locked",locked ? 0 : 1);
						}
					}
				});
				_Y.dices[index] = $(this);
			});
		
		
		// game throw controls
			var totalFieldWidth = _Y.table.find(".total.yamb-total").width();
			var ctrlBox = destination.find(".controls");
			var ctrlBoxWidth = ctrlBox.width();
			destination.find(".yamb-container").css({
				width: _Y.table.width() + ctrlBoxWidth - totalFieldWidth
			});
			ctrlBox.css({
				marginLeft: _Y.table.width() - totalFieldWidth
			});
		
		// undo
			this.btn_undo = destination.find(".controls a.undo").eq(0);
			this.btn_undo.hide();
				
		// display
			this.display = destination.find(".controls .display").eq(0);

		// throwButton
			this.btn_throw = destination.find(".controls input.throw-button").eq(0);
			
		// countdown
			this.interfaceReset(destination);
		
		this.init();
	},
	interfaceReset: function(destination) {
		this.countdown = 13 * this.games.length;
		this.disp_countdown = destination.find(".controls .yamb-countdown").eq(0);
		this.disp_countdown.attr("value", this.countdown).html(this.countdown);
		
		destination.find("td.field").html("").removeAttr("value");
		destination.find("tr.sum td").html("").removeAttr("value");
		
		this.throwCount = 3;
	},
	init: function() {
		var _Y = this;
		this.btn_throw.click(function(){
			_Y.locked = false;
			_Y.undo("hide");
			if(_Y.throwCount>0) {
				if(_Y.throwCount>2) {
					_Y.dices.each(function(){$(this).attr("locked", 0)});
				}
				
				var _BTN = $(this);
				_BTN.attr("disabled","disabled");
				
				_Y.locked = true;
				_Y.rolling = [1,1,1,1,1,1];
				_Y.rollDice(0);
				
				
				var timeOutFunction = function(){
					if(!_Y.isRolling()) {
						clearTimeout(_Y.interval);
						_Y.throwCount--;
						_Y.locked = false;
						_Y.holder.find(".display").html(3-_Y.throwCount);
						if(_Y.throwCount>0) {
							_BTN.attr("disabled",false);
						}
						
						// trigger onRollDice event for every game
						for(var i=0; i<_Y.games.length; i++) {
							game_object_name = "Yamb" + _Y.games[i].toTitleCase();
							var obj = eval("_Y." + game_object_name);
							if(obj.onRollDice) {
								obj.onRollDice();
							}
						}
					}else{
						_Y.interval = setTimeout(timeOutFunction, 100);
					}
				};
				_Y.interval = setTimeout(timeOutFunction, 100);
			}
		});
	},
	makeRow: function(rowGame, isSum) {
		var _Y = this;
		isSum = isSum ? true : false;
		
		var tr = $('<tr class="'+(isSum?"sum":"")+'" game="'+rowGame+'" />');
		tr.append('<td class="label">'+this._text(rowGame)+'</td>');
		for(var i=0; i<this.games.length; i++) {
			td = $('<td game_row="'+(rowGame)+'" game_column="'+this.games[i]+'"'+(isSum?'':' class="field"')+(isSum?'':' locked="0"')+' />');
			if(!isSum) {
				// set field-click event
				td.click(function(){_Y.fieldClick($(this))});
				td.mouseover(function(){
					if(!_Y.locked && $(this).hasClass("toplay")) {
						$(this).addClass("over-value");
						var val = _Y.getGameValue(rowGame);
						$(this).html(val)
					}
				});
				td.mouseout(function(){
					if(!$(this).hasClass("played")) {
						$(this).removeClass("over-value");
						$(this).html("");
					}
				});
				td.click(function(){
					if(!$(this).hasClass("toplay")) {
						$(this).removeClass("over-value");
					}
				});
			}
			tr.append(td);
		}
		tr.append('<td class="'+(isSum?"total":"empty")+'" />');
		this.table.append(tr);
	},
	fieldClick: function(td) {
		if(!this.locked) {
			var obj_name = "Yamb" + td.attr("game_column").toTitleCase();
			obj = eval("this." + obj_name);
			if(typeof obj != "undefined") {
				if(typeof obj.play != "undefined") {
					if( obj.play(td) ) {
						// reset game data
						this.locked = true;
						this.undo("show", td);
						this.throwCount = 3;
						this.holder.find(".display").html(0);
						this.countdown--;
						this.holder.find(".yamb-countdown").attr("value", this.countdown).html(this.countdown);
						this.updateSum(td);
						this.undoed = false;
						
						if(!this.countdown) {
							this.end();
						}
					}
					this.holder.find(".controls .throw-button").attr("disabled", false);
				}else{
					alert("Object " + obj_name + " doesn't support PLAY method.");
				}
			}else{
				alert("Object " + obj_name + " not found.");
			}
		}
	},
	isRolling: function() {
		var ret = false;
		for(var i=0; i<this.rolling.length; i++) {
			if(this.rolling[i]) {
				ret = true;
				break;
			}
		}
		return ret;
	},
	rollDice: function(index) {
		index = index>0?index:0;
		dice = this.holder.find("ul.dices li").eq(index);
		locked = parseInt(dice.attr("locked")); locked = locked>0 ? true : false;
		if(!locked) {
			var spins = Math.floor(Math.random()*5) + 1;
			this._roll(index,dice,spins,0);
		}else{
			this.rolling[index] = 0;
		}
		if(index<5) {
			this.rollDice(index+1);
		}
	},
	_roll: function(index, dice, spins, spin) {
		var _Y = this;
		if(spin<spins) {
			tmp = Math.floor(Math.random()*6) + 1;
			dice.attr("class","");
			dice.addClass("dice-"+(index+1));
			dice.addClass("value"+tmp);
			dice.attr("value",tmp);
			setTimeout(function(){
				_Y._roll(index, dice, spins, spin+1);
			}, 200);
		}else{
			_Y.rolling[index] = 0;
		}
	},
	undo: function(action, td) {
		var _Y = this;
		_Y.btn_undo.remove();
		
		var FieldsLeft = parseInt(_Y.countdown);
		
		if(action == "show" && FieldsLeft>0) {			
			var game_object_name = "Yamb" + td.attr("game_column").toTitleCase();
			GameObject = eval("_Y." + game_object_name);
			
			if(GameObject.cantUndo === true) {
				return;
			}
			
			_Y.btn_undo = $(_Y.btn_undo_html);
			_Y.btn_undo.html(_Y._text("undo"));
			_Y.display.before(_Y.btn_undo);
			
			_Y.btn_undo.show();
			_Y.btn_undo.click(function(){
				GameObject.undo(td);
				_Y.undoed = true;
				_Y.holder.find(".controls .throw-button").attr("disabled", true);
				td.html("");
				td.removeAttr("value");
				_Y.throwCount = 0;
				_Y.updateSum(td);
				_Y.holder.find(".display").html(3);
				_Y.countdown++;
				_Y.holder.find(".yamb-countdown").html(_Y.countdown);
				_Y.locked = false;
				_Y.undo("hide");
			});
		}
	},
	toPlay: function(td) {
		return td.hasClass("toplay");
	},
	getDices: function(justSelected) {
		justSelected = justSelected ? true : false;
		var dices = [0,0,0,0,0,0];
		this.dices.each(function(index){
			if(parseInt($(this).attr("locked"))>0) {
				dices[index] = parseInt($(this).attr("value"));
			}
		});
		if(justSelected) {
			tmp = [];
			for(x in dices) {
				if(dices[x] > 0) {
					tmp.push(dices[x]);
				}
			}
			dices = tmp;
		}
		return dices;
	},
	getGameValue: function(row_game) {
		row_game = "" + row_game;
		var value = 0;
		var dices = this.getDices();
		
		switch(row_game.toLowerCase()) {
			case "1":
			case "2":
			case "3":
			case "4":
			case "5":
			case "6":
				for(x in dices) {
					if(parseInt(dices[x]) == parseInt(row_game)) {
						value += parseInt(row_game);
					}
				}
				break;
			case "max":
				value = dices.sum();
				break;
			case "min":
				var selected = this.holder.find(".controls ul.dices").find("li[locked=1]").length;
				if(selected==5) {
					value = dices.sum();
				}else{
					value = 30;
				}
				break;
			case "straight":
				dices = this.getDices(true).sort();
				var straight = false;
				if(dices.length==5) {
					straight = true;
					for(var i=1; i<dices.length; i++) {
						if(dices[i]==dices[i-1] || (dices[i]-dices[i-1])!=1) {
							straight=false;
							break;
						}
					}
				}
				if(straight) {
					value = 66 - (3 - this.throwCount -1)*10;
				}else{
					value = 0;
				}
				break;
			case "trilling":
				value = this.getDices().sum2(3);
				value = value>0 ? 20+value : 0;
				break;
			case "full":
				sum = this.getDices().sum2();
				it_3 = 0;
				it_2 = 0;
				for(x in sum) {
					if(sum[x]>=3) {
						it_3 = x;
						sum[x] -= 3
					}
				}
				for(x in sum) {
					if(sum[x]==2) {
						it_2 = x;
					}
				}
				if(it_2>0 && it_3>0) {
					value = 30 + 3*it_3 + 2*it_2;
				}else{
					value = 0;
				}
				break;
			case "poker":
				value = this.getDices().sum2(4);
				value = value>0 ? value+40 : 0;
				break;
			case "yamb":
				value = this.getDices().sum2(5);
				value = value>0 ? value+50 : 0;
				break;
		}
		return value;
	},
	updateSum: function(td) {
		if(td) {
			var game_column = td.attr("game_column");
			var sumRow=td.parent().next();
			while(sumRow.length && !sumRow.hasClass("sum")) {
				sumRow = sumRow.next();
			}
			var isFirst = td.attr("game_row")=="1" ? true : false;
			if(sumRow.length) {
				var sumColumn = sumRow.find("td[game_column="+game_column+"]");
				var sum = 0; var val;
				var sum_row = sumColumn.attr("game_row");
				switch(sum_row) {
					case "sum1":
					case "sum3":
						var prevField = sumRow.prev().find("td.field[game_column="+game_column+"]").eq(0);
						while(prevField.hasClass("field")) {
							val = parseInt(prevField.html());
							val = val>0 ? val : 0;
							sum += val;
							prevField = prevField.parent().prev().find("td.field[game_column="+game_column+"]").eq(0);
						}
						sum = (sum_row=="sum1") ? (sum>=60 ? sum+30 : sum) : sum;
						sumColumn.html(sum).attr("value",sum);
						if(!isFirst) {
							break;
						}
						sumColumn = this.table.find("td[game_row=sum2][game_column="+game_column+"]");
					case "sum2":
						
						var first = parseInt(this.table.find("td.field[game_row=1][game_column="+game_column+"]").html());
						var max = parseInt(this.table.find("td.field[game_row=max][game_column="+game_column+"]").html());
						var min = parseInt(this.table.find("td.field[game_row=min][game_column="+game_column+"]").html());
						
						first = first>0 ? first : 0;
						max  = max>0 ? (min>0 ? max : 0) : 0;
						min = min>0 ? min : 0;
						
						sum = first * (max-min); sum = sum>0 ? sum : 0;
						sumColumn.html(sum).attr("value",sum);
						break;
				}
			}
			var total=0, total_1, total_2;
			
			this.table.find("tr.sum").each(function(){
				total_1 = 0;
				$(this).find("td[game_column]").each(function(){
					total_2 = parseInt($(this).html()); total_2 = total_2>0 ? total_2 : 0;
					total_1 += total_2;
				});
				total += total_1;
				$(this).find("td.total").html(total_1);
			});
			this.table.find(".yamb-total").html(total);
		}
	},
	end: function() {
		var total = parseInt(this.holder.find(".yamb-total").html());
		var destination = this.holder.find(".yamb-container").eq(0);
		
		var mask = $('<div id="yamb-end-mask" />');
		
		var h = destination.height();
		var paddingTop = parseInt(destination.css("padding-top"));
		var paddingBottom = parseInt(destination.css("padding-bottom"));
		h += (paddingTop>0?paddingTop:0) + (paddingBottom>0?paddingBottom:0);
		
		var w = destination.width();
		var paddingLeft = parseInt(destination.css("padding-left"));
		var paddingRight = parseInt(destination.css("padding-right"));
		w += (paddingLeft>0?paddingLeft:0) + (paddingRight>0?paddingRight:0);
		
		mask.css({
			height: h,
			opacity: 0.6
		});
		destination.prepend(mask);
		
		var container = $('<div id="yamb-end-container" />');
		var html = '<h2>'+this._text("game_end")+'</h2>';
		html += '<p><strong>'+this._text("result")+': <span class="end-result">'+total+'</span></strong></p>';
		html += '<p><a href="javascript:void(0)" onclick="YambRestart(\''+this.uuid+'\','+(this.multiplayer?1:0)+');">'+this._text("new_game")+'</a></p>';
		container.html(html);
		container.hide();
		destination.prepend(container);
		container.css({
			left: (w-container.width())/2,
			top: (h-container.height())/2
		});
		container.fadeIn("slow");
		
		
	},
	_text: function (str) {
		if(typeof YAMB_TEXT[str] == "undefined") {
			return str;
		}else{
			return YAMB_TEXT[str];
		}
	}
};